package logic

import (
	"context"
	"shop-cart/api/internal/utils"
	"shop-cart/taobaorpc/taobaorpc"

	"shop-cart/api/internal/svc"
	"shop-cart/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductUpdateLogic {
	return &ProductUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductUpdateLogic) ProductUpdate(req *types.ProductUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.TaoBaoRpc.ProductUpdate(l.ctx, &taobaorpc.ProductUpdateRequest{
		UserId:    req.UserId,
		ProductId: req.ProductId,
		Title:     req.Title,
		Price:     float32(req.Price),
	})
	if err != nil {
		return utils.ReturnResponse(err.Error(), 0, update)
	}
	return utils.ReturnResponse("修改购物车商品价格成功", 200, update)
}
